MESSAGE("\n+++ Started: PackageSoftware +++") 


# BEGIN: Configure files to be installed by packager (deb).
# http://www.cmake.org/pipermail/cmake/2010-May/037004.html
# 
       
# An interesting macro for installing subdirectories:
# NOTE: http://www.cmake.org/pipermail/cmake/2008-February/020114.html

# Install the executable itself.#works, same as the one below :)
# This is meant to be called by the init script.
INSTALL(FILES ${CMAKE_BINARY_DIR}/bin/carblogger_ui
# INSTALL(TARGETS "carblogger_ui"
      DESTINATION /usr/sbin/
      PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE
                    GROUP_READ GROUP_EXECUTE)

                   
# # Shorten the path name for convenience. Using random names now :)
SET(anci      ${CMAKE_CURRENT_SOURCE_DIR}/ancillary)
SET(ansil     ${anci}/maintainer_files)
SET(base      ${anci}/install-base)

# Ensure package scripts exist.
IF (NOT EXISTS ${ansil}/prerm)
    MESSAGE(FATAL_ERROR "File not found: ${ansil}/postinst")
ELSEIF(NOT EXISTS ${ansil}/postinst) 
    MESSAGE(FATAL_ERROR "File not found: ${ansil}/prerm")
ENDIF()

SET(CPACK_DEBIAN_PACKAGE_CONTROL_EXTRA ${ansil}/prerm;${ansil}/postinst)


SET(directories_to_install ${base}/etc;${base}/usr;${base}/var)
INSTALL(DIRECTORY ${directories_to_install}
    DESTINATION "/"
    PATTERN ".svn" EXCLUDE
    PATTERN "carblogger_runner" EXCLUDE) # I'll copy this one manually so I can make it executable.
    
INSTALL(FILES ${base}/etc/init.d/carblogger_runner
    DESTINATION "/etc/init.d"
    PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE
    GROUP_READ GROUP_EXECUTE
    WORLD_READ WORLD_EXECUTE) 
# END: Configure files to be installed by packager (deb).

# set (CPACK_DEBIAN_PACKAGE_SHLIBDEPS ON) # TODO: Find out how to make this work

#BEGIN Packaging
SET(CPACK_PACKAGE_CONTACT "jeff@linuxwest.com")
SET(CPACK_GENERATOR ${CPACK_GENERATOR};DEB)
include(CPack)  
# END Packaging.
